package com.raising.framework.servlet;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 配置Spring MVC的前端控制器
 * @author GaoYuan
 * @datetime 2018/2/3 上午10:47
 */
public class MyDispatcherServlet extends org.springframework.web.servlet.DispatcherServlet {
    @Override
    protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (logger.isInfoEnabled()) {
            logger.info(new StringBuilder("\n############################################################\n#").append("\n#  访问路径： ").append(request.getRequestURL()).append("\n#  访问页面： ").append(mv.getViewName()).append(".jsp\n").append("#\n############################################################"));
        }
        super.render(mv,request,response);
    }

    private static String getRequestUri(HttpServletRequest request) {
        String uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
        if (uri == null) {
            uri = request.getRequestURI();
        }
        return uri;
    }
}
